var Weapon = Class
		.extend({

			

			Shooting : function() {
				weapon = player.weapons[player.currentWeapon];
				if (this.reloading == false) {
					if (this.shoot == false) {
						if (this.shootDelay < this.shootDelayMax) {
							this.shootDelay++;
							if (this.shootDelay == this.shootDelayMax) {
								this.shoot = true;
							}

							if (this.scaleAim > this.normalScale) {
								this.scaleAim -= this.scaleShrink;
							}

							return;
						}
					}
					if (this.currentBullets > 0
							&& this.shoot == true) {
						this.shooted = true;
						player.weapons[player.currentWeapon].sound.currentTime=0;
						if (!gameOver){
						player.weapons[player.currentWeapon].sound.play();
						}
						this.currentBullets--;
						if (this.scaleAim < this.maxScale) {
							this.scaleAim += this.scaleGrow;
							for (var j = 0; j < this.bulletsPerShoot; j++) {

								if (this.aiming == true) {
									this.aiming = false;
								}
								for (var i = monsters.length - 1; i >= 0; i--) {

									var b = new bullet();

									if (((b.xPoint > monsters[i].xCoord) &&
											(b.xPoint < (monsters[i].xCoord + ((monsters[i].frameWidth * monsters[i].scale) - monsters[i].frameWidth / 5))))
											&& (b.yPoint > monsters[i].yCoord)
											&& (b.yPoint < monsters[i].yCoord
													+ (monsters[i].frameHeigth
															* monsters[i].scale * 2))) {

										if (b.yPoint < monsters[i].yCoord
												+ monsters[i].headHeight
												* monsters[i].scale + 5
												&& b.xPoint > (monsters[i].xCoord + ((monsters[i].frameWidth - monsters[i].headWidth) / 2)
														* monsters[i].scale)
												&& b.xPoint < ((monsters[i].xCoord + (monsters[i].frameWidth * monsters[i].scale)) - (((monsters[i].frameWidth * monsters[i].scale) - (monsters[i].headWidth * monsters[i].scale)) / 2)))

										{
											monsters[i].headShot = true
										}
										if (monsters[i].headShot == true) {
											monsters[i].HP -= this.damage
													* 2
													* player.damageMultiplicator;
											player.addPointsHit(
													monsters[i].points, true);
											player.totalHeadshots++; // new
											player.totalBulletsHit++; // new
											player.headshotStreak++; // new
											// double damage activator
										} else {
											if (b.yPoint > monsters[i].yCoord
													+ monsters[i].headHeight
													* monsters[i].scale + 5) {
												monsters[i].HP -= this.damage* player.damageMultiplicator; // new
												player.totalBulletsHit++; // new
												player.headshotshotStreak = 0; // new
												player.addPointsHit(
														monsters[i].points,
														false)
											}
										}

									}
									if (monsters[i].HP <= 0
											&& monsters[i].alive) {
										a.mobsKilled++;
										if (a.mobsKilled >= a.mobsForLevelMax) {
											a.Shoping();
										}
										monsters[i].alive = false;
										player
												.addPointsKill(monsters[i].points);
										if (monsters[i].bonus === true) {
											player.setDoubleDamage(10);
										}

									}
								}
							}
						}
					}
					this.shoot = false;
					this.shootDelay = 1;
				}

				else {
					if (this.reloading == true) {
						this.reloadingCounter++;
						if (this.reloadingCounter == this.reloadTime) {
							if (!gameOver){
								clipIn.play();}
								
							this.reloading = false;
							this.currentBullets = this.maxBulletsInMagazine;
							this.reloadingCounter = 0;
							this.extraMagazines--;
						}
					}
				}
			},
			nonShooting : function() {
				weapon = player.weapons[player.currentWeapon];
				if (this.reloading == true) {
					this.reloadingCounter++;
					if (this.reloadingCounter == this.reloadTime) {
					if (!gameOver){
								clipIn.play();}
								
						this.reloading = false;
						this.currentBullets = this.maxBulletsInMagazine;
						this.reloadingCounter = 0;
					}
				}
				if (this.shootDelay < this.shootDelayMax) {
					this.shootDelay++;
					if (this.shootDelay == this.shootDelayMax) {
						this.shoot = true;
					}
				}
				if (this.scaleAim > this.normalScale) {
					this.scaleAim -= this.scaleShrink;
				}
			},
			draw : function(index) {
				weapon = player.weapons[player.currentWeapon];
				if (this.reloading == true) {
					ctx.fillStyle = "red";
					ctx.strokeStyle = 'black';
					ctx.lineWidth = 2;
					ctx.font = "40px Impact";
					ctx.fillText("RELOADING", 420, 500);
					ctx.strokeText("RELOADING", 420, 500);
					ctx.fill();
					ctx.stroke();
				} else {
					this.getFrame(index);
					ctx.drawImage(this.img,
							this.currentFrame
							* this.frameWidth, 0,
							this.frameWidth,
							this.frameHeight, x
							- this.frameWidth
							+ this.floatLeft, 430,
							this.frameWidth * 2,
							this.frameHeight * 2);
					if (this.aiming != false) {
						ctx.drawImage(picturee, x - 6 * this.scaleAim, y - 6
								* this.scaleAim, 12.5 * this.scaleAim,
								12.5 * this.scaleAim);
					}
				}
				ctx.fillStyle = "white";
				ctx.font = "30px Defused";
				ctx.strokeStyle = "black"
				if (this.extraMagazines < 20) {
					ctx.fillText("Ammo :"+this.currentBullets + "/"
							+ this.maxBulletsInMagazine
							* this.extraMagazines, 700, 680);
					
				}
				if (this.extraMagazines > 20) {
					ctx.fillText("Ammo :"+this.currentBullets + "/"
							+ "\u221e", 700, 680);
					
				}
			},
			getFrame : function(index) {
				weapon = player.weapons[player.currentWeapon];
				if (this.shooted) {
					this.currentFrame = 1;
					this.shooted = false;
					return;
				}
				if (this.currentFrame > 0) {
					if (this.frameDelay < this.maxFrameDelay) {
						this.frameDelay++;
					} else {
						if (this.currentFrame < this.frames) {
							this.currentFrame++;
							this.frameDelay = 1;
						} else {
							this.currentFrame = 0;
						}
					}
				}
			},
			aim : function() {
			},
			drawScope : function() {
			},
			aim : undefined,
			drawScopeLines : function() {
			}

		});





function bullet() {
	var _this = player.weapons[player.currentWeapon];
	var x1 = (Math.random() * 2 * 4 * _this.scaleAim) - (4 * _this.scaleAim);
	var ylim1 = Math.sqrt((4 * _this.scaleAim) * (4 * _this.scaleAim) - x1 * x1);
	var y1 = Math.random() * 2 * ylim1 - ylim1 + 12;

	this.xPoint = x + x1;
	this.yPoint = y + y1;

}
function callShoot() {
	weapons[player.currentWeapon].Shooting();
}
function callNonShoot() {
	weapons[player.currentWeapon].nonShooting();
}